package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.GreTreeMoveLogLogic;
import cn.topevery.garden.entity.dto.GreTreeMoveLogDTO;
import cn.topevery.garden.entity.po.GreTreeMoveLog;
import cn.topevery.garden.entity.query.GreTreeMoveLogQuery;
import cn.topevery.garden.entity.vo.GreTreeMoveLogVO;
import com.github.dozermapper.core.Mapper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 迁移记录表
 *
 * @author code-generate
 * @date 2022-02-27
 */
@Api(tags = "迁移记录表")
@RestController
@RequestMapping("/greTreeMoveLog")
public class GreTreeMoveLogController extends BaseController {

    @Autowired
    private Mapper mapper;

    @Autowired
    GreTreeMoveLogLogic greTreeMoveLogLogic;


    /**
     * 获取迁移记录表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取迁移记录表页列表")
//    @PostMapping("/listPage")
    @PostMapping("/getList")
    public JsonResult<DataPager<GreTreeMoveLogVO>> listPage(@RequestBody GreTreeMoveLogQuery query) {
        return JsonResult.ok(greTreeMoveLogLogic.listPage(query));
    }

    @ApiOperation("新增/编辑 迁移记录表信息")
//    @PostMapping("/saveOrUpdate")
    @PostMapping("/save")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody GreTreeMoveLogDTO dto) {
        greTreeMoveLogLogic.saveOrUpdate(getUser().id.toString(),mapper.map(dto, GreTreeMoveLog.class));
        return JsonResult.ok(true);
    }

    @ApiOperation("通过Id获取详情")
//    @GetMapping("/getInfoById")
    public JsonResult<GreTreeMoveLogVO> getInfoById(@RequestParam Integer id) {
        GreTreeMoveLog entity = greTreeMoveLogLogic.getEntity(id);
        GreTreeMoveLogVO vo= mapper.map(entity, GreTreeMoveLogVO.class);
        return JsonResult.ok(vo);
    }

    @ApiOperation("根据自增ID批量删除")
//    @PostMapping("/deleteBatchById")
    @GetMapping("/delete")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        greTreeMoveLogLogic.deleteBatchById(getUser().id.toString(),ids);
        return JsonResult.ok(true);
    }

    @ApiOperation("导出迁移记录表信息")
    @GetMapping("/export")
    public void export(GreTreeMoveLogQuery query, HttpServletResponse response) {
        List<GreTreeMoveLogVO> list = greTreeMoveLogLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "迁移记录表", "sheet1", GreTreeMoveLogVO.class, "迁移记录表", response);
    }

    @ApiOperation("根据自增ID批量删除")
    @GetMapping("/deleteBatchById")
    public JsonResult<Boolean> delete(@RequestParam Integer[] ids) {
        greTreeMoveLogLogic.deleteBatchById(getUser().id.toString(),ids);
        return JsonResult.ok(true);
    }
    @ApiOperation("通过Id获取详情")
    @GetMapping("/getById")
    public JsonResult<GreTreeMoveLogVO> getTreeFamousById(@RequestParam Integer id) {
        GreTreeMoveLog entity = greTreeMoveLogLogic.getEntity(id);
        GreTreeMoveLogVO vo= mapper.map(entity, GreTreeMoveLogVO.class);
        return JsonResult.ok(vo);
    }
}
